export default {
    set: function (key, value, expires) {
        let data = {
            value: value,
            time: Date.now() / 1000, //记录存储的时间戳
            expire: expires //记录过期时间，单位秒
        }
        localStorage.setItem(key, JSON.stringify(data))
    },

    get: function (key) {
        let value = localStorage.getItem(key)
        if (!value) {
            return null
        }

        value = JSON.parse(value)
        if (Date.now() / 1000 - value.time > value.expire) {
            localStorage.removeItem(key);
            return null
        }

        return value.value
    },

    remove: function (key) {
        localStorage.removeItem(key);
    },
    clear: function () {
        localStorage.clear()
    }
}